import axios from 'axios';

import { User } from '../models/user';

// TODO: 包装一下 axios

export const login = async (username: string, password: string): Promise<User> => {
  return await axios.post('/api/user/login', { username, password }).then((resp) => resp.data);
};

export const register = async (username: string, password: string): Promise<User> => {
  return await axios.post('/api/user/register', { username, password }).then((resp) => resp.data);
};

export const logout = async (): Promise<{ ok: boolean }> => {
  return await axios.post('/api/user/logout').then((resp) => resp.data);
};

export const load = async (): Promise<User> => {
  return await axios.get('/api/user/current').then((resp) => resp.data);
};
